﻿using Greg.XmlEditor.Presentation.Presenters;
namespace Greg.XmlEditor.Presentation.Commands.Concrete
{
	public class NewCommand : CommandBase
	{
		private readonly MasterPresenter presenter;
		private readonly IDocumentPresenterFactory factory;

		public NewCommand(MasterPresenter presenter, IDocumentPresenterFactory factory)
		{
			this.presenter = presenter;
			this.factory = factory;
		}

		/// <summary>
		/// Refreshes the command state.
		/// </summary>
		public override void Refresh()
		{
			this.IsEnabled = true;
		}

		/// <summary>
		/// Executes the command logics.
		/// </summary>
		public override void Invoke()
		{
			var document = this.factory.CreateDocument();
			this.presenter.Documents.Add(document);
			this.presenter.CurrentDocument = document;
		}
	}
}
